import unittest # 导单元测试三方库
from unit_demo.Ca import jisuanqi #导被测试代码
from  HTMLTestRunner import  HTMLTestRunner



class Ca_test(unittest.TestCase):   #建立一个执行用例的类，继承三方库的基类
    #设置几条用例test作为前缀############################################
    def test_jia_01(self):
        JSQ = jisuanqi()
        r = JSQ.jia(1,2)
        self.assertEqual(r,2,msg="test_jia_01 不通过!")
        print('test_jia_01，本条用例通过！')
    def test_jia_02(self):
        JSQ = jisuanqi()
        r = JSQ.jia(1,2)
        self.assertGreater(r,1,msg="test_jia_02 不通过!")
        print('test_jia_02，本条用例通过！')
    def test_jian_01(self):
        JSQ = jisuanqi()
        r = JSQ.jian(10,5)
        self.assertEqual(5,r,msg="test_jian_01 不通过！")
        print("test_jian_01，本条用例通过！")
    def test_jian_02(self):
        JSQ = jisuanqi()
        r = JSQ.jian(10,5)
        self.assertGreater(10,r,msg="test_jian_02 不通过！")
        print("test_jian_02，本条用例通过！")
    def test_cheng_01(self):
        JSQ = jisuanqi()
        r = JSQ.cheng(10,5)
        self.assertEqual(20,r,msg="test_cheng_01 不通过！")
        print("test_cheng_01，本条用例通过！")
    def test_cheng_02(self):
        JSQ = jisuanqi()
        r = JSQ.cheng(10,5)
        self.assertGreater(55,r,msg="test_cheng_02 不通过！")
        print("test_cheng_02，本条用例通过！")
    def test_chu_01(self):
        JSQ = jisuanqi()
        r = JSQ.chu(10,5)
        self.assertEqual(2,r,msg="test_chu_01 不通过！")
        print("test_chu_01，本条用例通过！")
    def test_chu_02(self):
        JSQ = jisuanqi()
        r = JSQ.chu(10,5)
        self.assertGreater(3,r,msg="test_chu_02 不通过！")
        print("test_chu_02，本条用例通过！")
    #设置几条用例test作为前缀############################################

    #API
    # def setUp(self):
    #     print("测试开始")
    # def tearDown(self):
    #     print("测试结束")
    @classmethod
    def setUpClass(cls):
        print("测试开始")
    @classmethod
    def tearDownClass(cls):
        print("测试结束")
    #API




if __name__ == "__main__":
    #unittest.main()
###TextTestRunner##########
    # suit = unittest.TestSuite()
    # suit.addTest(Ca_test("test_chu_01"))
    # runner = unittest.TextTestRunner()
    # runner.run(suit)

    ########loader##########
    suite = unittest.TestSuite()
    suite.addTests(unittest.TestLoader().loadTestsFromName("Demo.Ca_test"))
    # runner = unittest.TextTestRunner(verbosity=2)
    # runner.run(suit)

    ###生成系统自带的测试报告#########
    with open('report1.txt','w',encoding="utf-8") as file:
        unittest.TextTestRunner(stream=file,verbosity=2).run(suite)

###生成HTML测试报告#########
    # with open('report5.html','w',encoding='utf-8') as file:
    #     HTMLTestRunner(stream=file,verbosity=2,title='测试报告',description='计算器的测试报告').run(suite)
    ###print("aasdasdsadsadsa")